package com.bb.blog.code.proxy;

import com.bb.blog.code.spring.Sout;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy implements InvocationHandler,Sout {
    public static void main(String[] args) {
        Sout o = (Sout) Proxy.newProxyInstance(JdkProxy.class.getClassLoader(), new Class[]{Sout.class}, new JdkProxy());
        o.sout();
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理了");
        return method.invoke(this,args);
    }

    @Override
    public void sout() {
        System.out.println("实际对象");
        sout2();
    }

    @Override
    public void sout2() {
        System.out.println("实际对象2");
    }
}
